package com.ymk.cmd;

import com.ymk.base.cmd.ACmd;
import com.ymk.base.cmd.CmdSign;
import com.ymk.base.exception.MallException;
import com.ymk.base.utlis.ParamsBuilder;
import com.ymk.bo.work.WorkBO;
import com.ymk.core.code.cmd.WorkCmdCode;
import com.ymk.core.constants.WxConstants;
import com.ymk.service.IWorkService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Objects;

@Service
public class WorkHistoryCmd extends ACmd {

    @Override
    public CmdSign executeSop(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        WorkBO reqData = super.getData(sign, WorkBO.class);

        ParamsBuilder paramsBuilder = ParamsBuilder.newBuild()
                .addParam("loadWorkImg",true)
                .addParam("loadWorkType",true)
                .addParam("workIdList",reqData.getWorkIdList());

        List<WorkBO> workBOList = workService.listForPage(paramsBuilder.build());
        respSign.setSource(super.getSource(workBOList));

        return respSign;
    }

    @Override
    public String getCmdCode() {
        return WorkCmdCode.WORK_HISTORY;
    }

    @Override
    public CmdSign verify(HttpServletRequest request, CmdSign sign) throws Exception {
        WorkBO reqData = super.getData(sign, WorkBO.class);
        String openId = request.getHeader(WxConstants.X_WX_OPENID);
        if (StringUtils.isBlank(openId)) {
            throw new MallException("请求异常,header未发现openID");
        }
        if(Objects.isNull(reqData.getWorkIdList())){
            throw new MallException("岗位id结合不能为空");
        }
        return null;
    }


    @Override
    public boolean anon(CmdSign sign) {
        return true;
    }

    @Autowired
    private IWorkService workService;
}